﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace Common
{
    /// <summary>
    /// String extension methods
    /// </summary>
    public static class StringExtensions
    {
        /// <summary>
        /// Determines wheter the start of the string matches the specified pattern ignoring culture and case
        /// </summary>
        /// <param name="str">The string to check</param>
        /// <param name="pattern">The pattern to check for</param>
        /// <returns>True if the start of the string matches the specified pattern ignoring culture and case</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1309:UseOrdinalStringComparison", MessageId = "System.String.StartsWith(System.String,System.StringComparison)")]
        public static bool StartsWithInvariant(this String str, String pattern)
        {
            Contract.Requires(str != null);
            Contract.Requires(pattern != null);
            return str.StartsWith(pattern, StringComparison.InvariantCultureIgnoreCase);
        }

        /// <summary>
        /// Determines wheter the end of the string matches the specified pattern ignoring culture and case
        /// </summary>
        /// <param name="str">The string to check</param>
        /// <param name="pattern">The pattern to check for</param>
        /// <returns>True if the end of the string matches the specified pattern ignoring culture and case</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1309:UseOrdinalStringComparison", MessageId = "System.String.EndsWith(System.String,System.StringComparison)")]
        public static bool EndsWithInvariant(this String str, String pattern)
        {
            Contract.Requires(str != null);
            Contract.Requires(pattern != null);
            return str.EndsWith(pattern, StringComparison.InvariantCultureIgnoreCase); 
        }
    }
}
